package cn.com.css.taxInspection.workflow.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workflow.entity.WorkflowInspectionHearEntity;
import cn.com.css.taxInspection.workflow.mapper.WorkflowInspectionHearMapper;
import cn.com.css.taxInspection.workflow.service.WorkflowInspectionHearService;

@Service("workflowInspectionHearService")

public class WorkflowInspectionHearServiceImpl
        extends ServiceImpl<WorkflowInspectionHearMapper, WorkflowInspectionHearEntity>
        implements WorkflowInspectionHearService {
    @Override
    public void updateByWorkflowInspectionHearEntity(WorkflowInspectionHearEntity workflowInspectionHear) {
        this.updateById(workflowInspectionHear);
    }

    @Override
    public List<List<WorkflowInspectionHearEntity>> getByStateCodeAndInspectionMan11(List<String> listSateCode,
                                                                                     String currentUserId, String currentDeptId) {
        List<List<WorkflowInspectionHearEntity>> listWorkflowInspectionHearEntityList = new ArrayList<>();
        LambdaQueryWrapper<WorkflowInspectionHearEntity> queryWrapper1 = Wrappers.lambdaQuery();
        queryWrapper1.in(WorkflowInspectionHearEntity::getStateCode, listSateCode);
        queryWrapper1.like(WorkflowInspectionHearEntity::getInspectionMan11, currentUserId);
        queryWrapper1.orderByDesc(WorkflowInspectionHearEntity::getCreateTime);
        List<WorkflowInspectionHearEntity> list1 = this.list(queryWrapper1);
        List<WorkflowInspectionHearEntity> list1Handle = new ArrayList<>();
        for (WorkflowInspectionHearEntity workflowInspectionHearEntity : list1) {
            String debugtaxorg = workflowInspectionHearEntity.getDebugtaxorg();
            String inspectionTaxorg11 = workflowInspectionHearEntity.getInspectionTaxorg11();
            if (TsBqUtils.isNotNull(debugtaxorg)) {
                if (currentDeptId.equals(debugtaxorg)) {
                    list1Handle.add(workflowInspectionHearEntity);
                }
            } else {
                if (currentDeptId.equals(inspectionTaxorg11)) {
                    list1Handle.add(workflowInspectionHearEntity);
                }
            }
        }
        listWorkflowInspectionHearEntityList.add(list1Handle);
        List<WorkflowInspectionHearEntity> list2 = this.list();
        listWorkflowInspectionHearEntityList.add(list2);
        return listWorkflowInspectionHearEntityList;
    }

    @Override
    public List<List<WorkflowInspectionHearEntity>> getByStateCodeAndInspectionMan21(List<String> listStateCode,
                                                                                     String currentUserId) {
        List<List<WorkflowInspectionHearEntity>> listWorkflowInspectionHearEntityList = new ArrayList<>();
        LambdaQueryWrapper<WorkflowInspectionHearEntity> queryWrapper1 = Wrappers.lambdaQuery();
        queryWrapper1.in(WorkflowInspectionHearEntity::getStateCode, listStateCode);
        queryWrapper1.like(WorkflowInspectionHearEntity::getHearMan21, currentUserId);
        queryWrapper1.orderByDesc(WorkflowInspectionHearEntity::getCreateTime);
        List<WorkflowInspectionHearEntity> list1 = this.list(queryWrapper1);
        listWorkflowInspectionHearEntityList.add(list1);
        List<WorkflowInspectionHearEntity> list2 = this.list();
        listWorkflowInspectionHearEntityList.add(list2);
        return listWorkflowInspectionHearEntityList;
    }

    @Override
    public WorkflowInspectionHearEntity getByJcajxxuuid(String id) {
        return this.getById(id);
    }

}